package com.ccys.cms.controller.productAndService;


import com.ccys.cms.service.productAndService.MedicalSService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.productAndService.MedicalServiceDto;
import com.ccys.db.dto.web.productAndService.NumEnum;
import com.ccys.db.entity.TblMedicalService;
import com.ccys.db.mapper.TblMedicalServiceMapper;
import com.ccys.db.vo.web.productAndService.GetMedicalServiceListVo;
import com.ccys.db.vo.web.productAndService.IdNameVo;
import com.ccys.db.vo.web.productAndService.MedicalServiceVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/productAndService")
@Api(tags = "医疗服务")
public class MedicalServiceController {


    @Resource
    private MedicalSService service;

    @Resource
    private TblMedicalServiceMapper mapper;

    @PostMapping("medicalService")
    @ApiOperation("新增")
    @Transactional
    public ResponseResult insert(TblMedicalService model) {

        int i = service.insertOrUpdate(model);
        return ResponseResult.update(i);
    }

    @PutMapping("medicalService")
    @ApiOperation("修改")
    @Transactional
    public ResponseResult update(TblMedicalService model) {

        int i = service.insertOrUpdate(model);
        return ResponseResult.update(i);
    }


    @GetMapping("medicalService/detail")
    @ApiOperation("根据id查询")
    public ResponseResult<TblMedicalService, Object> getById(String id) {

        return ResponseResult.success(service.findEntityById(id));
    }


    @DeleteMapping("medicalService")
    @ApiOperation("根据Id删除")
    @Transactional
    public ResponseResult delete(String id) {

        TblMedicalService model = new TblMedicalService();
        model.setId(id);
        model.setDelFlag(NumEnum.DEL.getCode());
        int i = service.updateEntityById(model);
        return ResponseResult.update(i);
    }


    @GetMapping("medicalService")
    @ApiOperation(value = "查询分页", notes = "排序字段 t1.name_admin/ t5.group_name / t6.name(指的是国家名称) / t1.price / t3.name (category的name) / t4.name(supplier的name)  / t1.status /t2. user_fullname / t1.created_on ")
    public ResponseResult<PageInfo<MedicalServiceVo>, Object> getPage(MedicalServiceDto dto) {

        return service.getPage(dto);
    }


    @GetMapping("medicalService/list")
    @ApiOperation(value = "查询集合")
    public ResponseResult<List<GetMedicalServiceListVo>, Object> getList() {
        List<GetMedicalServiceListVo> list = mapper.getMedicalServiceList();
        return ResponseResult.success(list);
    }
}
